
#include "main.h"

#include "uart.h"
#include "uart_test.h"
#include "uart_utils.h"
#include "../../test/ringbuffer_test/ringbuffer_test.h"

#include "ringbuffer.h"

#include "sysclk.h"



struct rt_ringbuffer rx_buffer;		// recv ringbuffer
uint8_t rx_buffer_data[128];		// recv ringbuffer data

uint8_t rx_data;		// recv data

int mymain(void)
{
	/* init system clock -- default 72M */
	sys_clk_init();
	
	/* init systick */
	delay_init(72);

	/* init uart interface*/
	struct uart_device *pDev = find_uart_device("uart1");
	pDev->init(pDev, 115200, 8, 1, 0);
	
	/* init recv ringbuffer */
	rt_ringbuffer_init(&rx_buffer, rx_buffer_data, sizeof(rx_buffer_data));
	
	while(1)
	{	
		/* recv test*/
		if(rt_ringbuffer_data_len(&rx_buffer) > 0)
		{
			rt_ringbuffer_getchar(&rx_buffer, &rx_data);
			pDev->send(pDev, &rx_data, 1);
		}
		
		/* delay 200ms */
		delay_ms(200);
	}
}




